/*
 * @Author: your name
 * @Date: 2021-10-19 16:29:50
 * @LastEditTime: 2021-10-26 14:15:21
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \wx-x-mai\pages\workService\gxuniversity\firstpage\index.js
 */
/**
 * @see
 */
const app = getApp()
let paging = {
  current: 1,
  size: 10,
  total: 0
}
Page({
  data: {
    list: [],
    type: '',
    appMsg: {
      type: '',
      show: false
    },
    classId: "",
    oOrderDetails: {}, // 申请记录内容
    beginSchoolYear: "",
    endSchoolYear: "",
    courseType: "", //课程类型
  },
  onLoad(options) {
    console.log(options, '接收参数');
    this.setData({
      beginSchoolYear: options.beginSchoolYear,
      endSchoolYear: options.endSchoolYear,
      courseType: options.courseType,
      classId: options.classId
    })
    this.notPassStudent();
  },
  onUnload() {
    paging = {
      current: 1,
      size: 10,
      total: 0
    }
  },
  /**
   * @see 监听页面滚动到底部加载更多
   */
  onReachBottom() {
    if (paging.total <= this.data.list.length) {
      return
    } else {
      paging.current++
      this.notPassStudent()
    }
  },

  notPassStudent() {
    const request = {
      current: paging.current,
      size: paging.size,
      beginSchoolYear: this.data.beginSchoolYear,
      endSchoolYear: this.data.endSchoolYear,
      courseType: this.data.courseType,
      classId: this.data.classId
    }
    wx.showLoading({
      title: '加载中',
    })
    wx.$API['workService/notPassStudent'](request).then((result) => {
      wx.stopPullDownRefresh()
      setTimeout(function () {
        wx.hideLoading()
      }, 1000)
      // console.log(result, '拿到列表数据')
      const {
        data
      } = result

      const dataitem = data.data;
      const total = data.total;
      paging.total = total;
      if (dataitem.length === 0) {
        this.setData({
          appMsg: {
            type: 'none',
            show: true
          }
        })
      } else {
        dataitem.forEach((item) => {})
        this.setData({
          list: this.data.list.concat(dataitem)
        })
      }
    }).catch((error) => {
      wx.stopPullDownRefresh()
      wx.showToast({
        title: error,
        icon: 'error',
        duration: 1200
      })
      setTimeout(function () {
        wx.hideLoading()
      }, 1000)
    })
  },

  /**
   * @see 重置数据
   */
  refreshData() {
    paging = {
      current: 1,
      size: 15,
      total: 0
    }
    this.setData({
      list: []
    })
    this.notPassStudent();
  },
  /**
   * @see 上拉刷新
   * 
   * 
   * 
   * 
   * 
   * 
   * 
   * 
   * 
   * 
   * 
   * 
   * 
   * 
   * 
   */
  onPullDownRefresh() {
    this.refreshData()
  }

})